package com.csaba.connector.citi.parser;

import java.io.IOException;
import java.io.Reader;

import net.htmlparser.jericho.Source;
import net.htmlparser.jericho.StartTag;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

public class LoginParser
{
	public static String parseNextURL( final Reader reader ) throws IOException
	{
		return CitiParser.parseNextURL("name", "F1", "action", reader);
	}

	public static String parseMainMenuURL( final Reader reader ) throws IOException
	{
		//<FRAME ID=NavChans NAME="" MARGINWIDTH=0 MARGINHEIGHT=0 FRAMEBORDER=0 NORESIZE SCROLLING=NO SRC="/HomeBankingSecure/insess.asp?_D=NavFrameSet&_C=HTML&_F=&_T=CH&NavChans=&_S=2&_V=NavChans&_NS=2&_TS=1225880387">
		//home1hu.cbol.citibank.hu/HomeBankingSecure/insess.asp?_D=NavFrameSet&_C=HTML&_F=&_T=CH&NavChans=&_S=2&_V=NavChans&_NS=2&_TS=1225880387
		return CitiParser.parseNextURL("ID", "NavChans", "SRC", reader);
	}

	public static NameValuePair parseValue( final Reader reader, final String name ) throws IOException
	{
		final Source source = new Source(reader);
		final StartTag startTag2 = source.getNextStartTag(0, "name", name, true);
		//_AUTHTOK_CITIDIRECT_=010101E1%252C083B9618BB9A253E%252CWhkBY0833jQ5qV7MiW9VVL%252F65M4%252B9j%252Fo9am7lSGBjgp%252BxwLypStokATzkGINd%252FBPho3yb1IKOGAosLu7tY%252BXWgJdO2LJCAjiEopM6grXpBqrB3JpNr4PrmGY15N2ufwJEZ1SqTOfesPZrAO0UccWiCQGtDQzL81d4kG8yrRcy%252Bg%253D%252CMFExCzAJBgNVBAYTAlVTMRIwEAYDVQQKEwlDaXRpZ3JvdXAxIDAeBgNVBAsTF0NlcnRpZmljYXRpb24gQXV0aG9yaXR5MQwwCgYDVQQLEwNDQTA%253D%252C1124469883%252CDHmobyiF%252FyO%252FmGs2pEtjNo9eEhL2oBlfTKoWDqVTXhiDjpt0VWEDQFl1piFZ3vQEEd%252F2k7jcU6shdnucRZRW%252BKBLxJo6cZFpo4H6A%252F7UbTwSZbwWAfma8SHLhoZKIwmlXLZlTai5%252FfPTezcvkTIX93mIjdtD01NqqLHZAGkCORw%253D%257CM1%252CkFYK2mCnQUVMtBXU7t1hFoEVvTsgKXE5euCwTJlZd0BUw%252BU1HWf2WLdE3Z%252Fg8uW3MWJ1AqbHeIeBkFA5ul%252FuRIn5fq3oukTtVVKRnfgnX2gBPGZR58DfBepauwFutnaNxE6JG1PmGA7VC3AIwakTdfgpub9ipgsS86cmFX3gDF%252BbG%252B3yhswLWA%253D%253D%257CD8TU9%252FUv9n47xBJxq8Zok6sNit12%252F77hi%252BntmPTqB7eF9TH8mbgxDrMHnav7M44yH1N4KWz0gNb%252BKV6ZmLJYLEsoBj1rDEdwYSehN53furH0l5b50oGwPFN%252FkHNiqlfZslukDhwJLyLITgC1Ue5t4FVOR5mXdeIwYYvvc0BFn4fXKouO7eRIb09y48h32KFuSWf63fQu7L2t97rw%252BPD5iMNJAK%252F8c2%252FJcPLdy3X1h6dMUlHz9VmQj5Z5NVYQVg%252Bk82EkagN4J7lA9%252BAlF6xc%252FvLFGYGEWcDxMV4Lk1tRSODMPe%252FnQys8TkQ%253D%253D
		final String value = startTag2.getAttributeValue("value");
		return new BasicNameValuePair(name, value);
	}
}
